package com.itqf.mybatis;

import com.itqf.mapper.AuthorMapper;
import com.itqf.pojo.Author;
import com.itqf.utils.SqlSessionUtils;
import org.apache.ibatis.session.SqlSession;

/**
 * projectName: mybatisgp8
 *
 * @author: 赵伟风
 * time: 2021/7/30 16:59
 * description:测试一级缓存
 */
public class UseIf {

    public static void main(String[] args) {

        /**
         *
         * mybatis的一级缓存是默认开启的!
         *   一个缓存的范围: 统一sqlSession对象[同一个SqlSession不同mapper]
         *
         *
         */

        SqlSession sqlSession = SqlSessionUtils.openSession();


        AuthorMapper mapper = sqlSession.getMapper(AuthorMapper.class);


        Author author = mapper.queryByPriamryKey(1);
        System.out.println("author = " + author);

        System.out.println("----------------");

        Author author1 = mapper.queryByPriamryKey(1);
        System.out.println("author1 = " + author1);

        System.out.println("----------------");
        AuthorMapper mapper1 = sqlSession.getMapper(AuthorMapper.class);

        Author author2 = mapper1.queryByPriamryKey(1);
        System.out.println("author2 = " + author2);

        sqlSession.close();

        System.out.println("-------------------------");
        SqlSession sqlSession1 = SqlSessionUtils.openSession();
        AuthorMapper mapper2 = sqlSession1.getMapper(AuthorMapper.class);

        Author author3 = mapper2.queryByPriamryKey(1);

        System.out.println("author3 = " + author3);

        sqlSession1.close();


    }

}
